<template>
  <div class="StylisticSer">
    <!-- 页面主体信息区域 -->
    <div class="outermostMargin">
      <div class="ALittleBit">
        <div class="carousel">
          <img style="width: 100%;height: 165px;" :src="bannerurl" v-if="bannerurl" />
        </div>
        <!--区划-->
        <area-select @load="selectLoad" @loadClearsearch='Clearsearch' />
        <div class="listBox">
          <div v-for="(item, index) in list" :key="index" style="max-height: 200px;">
            <!-- 通讯录行主体部分 -->
            <div class="mainBox">
              <div class="leftP" @click="toDet(item)">
                <div class="headp">
                  <img style="width: 100px;" :src="item.url? picUrl(item.url): require('../../assets/mr/'+serviceType+'.png')" />
                </div>
                <div class="text">
                  <div class="namePhone">
                    <p class="itemname">{{item.serviceName}}</p>
                  </div>
                  <!-- <div class="posArea" v-if="$route.query.title == '找物业'"> -->
                    <div class="posArea" v-if="$route.query.title == '其他便民服务'">
                    <p class="item">发布时间：{{item.updateTime}}</p>
                    <p class="item">联系人： {{item.contacts}}</p>
                    <p class="item">联系电话： {{item.servicePhone}}</p>
                    <p class="item overthress">详情： {{item.serviceCase}}</p>
                  </div>
                  <div class="posArea" v-else-if="$route.query.title == '要购物'">
                    <p class="item">联系人： {{item.contacts}}</p>
                    <p class="item">联系电话： {{item.servicePhone}}</p>
                    <p class="item overthress">咨询简述： {{item.serviceCase}}</p>
                  </div>
                  <div class="posArea" v-else-if="$route.query.title == '要出行'">
                    <p class="item">运营起止时间：{{item.fees}}</p>
                    <p class="item">联系人： {{item.contacts}}</p>
                    <p class="item">联系电话： {{item.servicePhone}}</p>
                    <p class="item overthress">班次号： {{item.serviceCase}}</p>
                  </div>
                  <div class="posArea" v-else-if="$route.query.title == '找美食'">
                    <p class="item">联系人： {{item.contacts}}</p>
                    <p class="item">饭店联系电话： {{item.servicePhone}}</p>
                    <p class="item overthress">饭店简述： {{item.serviceCase}}</p>
                  </div>
                  <div class="posArea" v-else-if="$route.query.title == '找健康'">
                    <p class="item">联系人： {{item.contacts}}</p>
                    <p class="item">机构联系电话： {{item.servicePhone}}</p>
                    <p class="item overthress">机构简述： {{item.serviceCase}}</p>
                  </div>
                  <div class="posArea" v-else-if="$route.query.title == '街坊电话本'">
                    <p class="item">联系人： {{item.contacts}}</p>
                    <p class="item">服务联系电话： {{item.servicePhone}}</p>
                    <p class="item overthress">服务联系地址： {{item.serviceCase}}</p>
                  </div>
                </div>
              </div>
              <img class="phone" src="../../assets/treasureChest/thiredP/phoneIcon765.png" @click="callOut(item.servicePhone)" />
            </div>
            <van-divider />
          </div>
        </div>
      </div>
      <van-pagination class="pages" v-model="currentPage" :page-count="allcount" force-ellipses @change="requestPostProblemService" />
    </div>
    
  </div>
</template>
<script>
  import AreaSelect from "@/components/AreaSelect.vue";
  export default {
    name: 'TelephoneBook',
    data() {
      return {
        list: [],
        dataAreaCode: sessionStorage.getItem("dataAreaCode"),
        serviceType: this.$route.query.serviceType || 1,
        bannerurl: "",
        isChoose: false, //是否进行了街镇的选择
        currentPage: 1,
        allcount: 1,
      };
    },
    components: {
      AreaSelect
    },
    created() {
      if (this.$route.query.title) {
        this.setTitle(this.$route.query.title);
      }
      this.slow.getBanner(this.$route.query.title, url => {
        this.bannerurl = url;
      });
      this.requestPostProblemService();
    },
    methods: {
      selectLoad(v, search) {
        this.isChoose = true; //进行街镇选择了，isChoose为true
        this.dataAreaCode = v;
        this.currentPage = 1;
        this.requestPostProblemService(v, search);
      },
      Clearsearch(v, search){
        this.isChoose = true; //进行街镇选择了，isChoose为true
        this.dataAreaCode = v;
        this.currentPage = 1;
        this.requestPostProblemService(v, search);
      },
      back() {
        this.$router.isBack = true; // 将返回状态置为触发态，以边路由监听触发返回动画
        this.$router.back(); // 路由向后退一步
      },
      callOut(phoneNum) {
        this.$dialog
          .confirm({
            title: "拨打电话",
            message: "是否拨号：" + phoneNum
          })
          .then(() => {
            window.location.href = "tel://" + phoneNum;
          })
          .catch(() => {});
      },
      toDet(msg) {
        this.$router.push({
          path: "/serviceDet",
          query: {
            detData: msg,
            title: this.$route.query.title
          }
        });
      },
      // 请求法律服务数据
      requestPostProblemService(v , search) {
        if (this.isChoose == true) { //进行街镇选择
          if (this.slow.isAuth) {
            // if (this.slow.isAuth && this.slow.userInfo.subscribe != 0) {
            console.log('进行了区划选择并注册过了')
            this.post("convenient_people/loadInfo/", {
                pageSize: 10,
                pageIndex: this.currentPage,
                dataAreaCode: this.dataAreaCode,
                title: search,
                startTime: "2018-10-06 00:00:00",
                endTime: "2020-11-06 00:00:00",
                serviceType: this.serviceType
              })
              .then(res => {
                this.allcount = Number(res.pageInfo.pageCount);
                this.list = res.list
              })
              .catch(err => {});
          } else {
            console.log('进行了区划选择，没有注册过了')
            this.post("convenient_people/loadInfo/", {
                pageSize: 10,
                pageIndex: this.currentPage,
                dataAreaCode: this.dataAreaCode,
                title: search,
                startTime: "2018-10-06 00:00:00",
                endTime: "2020-11-06 00:00:00",
                serviceType: this.serviceType
              })
              .then(res => {
                this.allcount = Number(res.pageInfo.pageCount);
                this.list = res.list
              })
              .catch(err => {});
          }
        } else {
          if (this.slow.isAuth) { //如果注册了，默认当前区划
          // if (this.slow.isAuth && this.slow.userInfo.subscribe != 0) {
            console.log('没有进行区划选择并注册过了')
            this.post("convenient_people/loadInfo/", {
                pageSize: 10,
                pageIndex: this.currentPage,
                dataAreaCode: this.dataAreaCode,
                title: search,
                startTime: "2018-10-06 00:00:00",
                endTime: "2020-11-06 00:00:00",
                serviceType: this.serviceType
              })
              .then(res => {
                this.allcount = Number(res.pageInfo.pageCount);
                this.list = res.list
              })
              .catch(err => {});
          } else { //如果没有注册，dataAreaCode:'' ,显示河口区层级发布的
            console.log('没有进行区划选择并没有注册过')
            this.post("convenient_people/loadInfo/", {
                pageSize: 10,
                pageIndex: this.currentPage,
                title: search,
                dataAreaCode: '',
                startTime: "2018-10-06 00:00:00",
                endTime: "2020-11-06 00:00:00",
                serviceType: this.serviceType
              })
              .then(res => {
                this.allcount = Number(res.pageInfo.pageCount);
                this.list = res.list
              })
              .catch(err => {});
          }
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  @import "~@/smobile.scss";
  .overthress {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
  }
  .StylisticSer {
    overflow-y: unset !important;
    .header {
      padding: $sm-spaceing-block-sm 0 $sm-spaceing-block-sm 0;
      position: absolute;
      width: $sm-img-per-max;
      height: 21px;
      background: $sm-bg-color;
      z-index: 2;
      display: flex;
      flex-direction: row nowrap;
      justify-content: flex-start;
      .backIcon {
        position: absolute;
        white-space: nowrap;
        height: $sm-icon-px-md;
        z-index: 4;
        .iconImage {
          height: $sm-icon-px-md;
          width: $sm-icon-px-md;
          transform: rotateY(180deg);
        }
      }
      .theme {
        position: absolute;
        font-weight: bold;
        width: $sm-img-per-max;
        text-align: center;
        white-space: nowrap;
        z-index: 3;
      }
    }
    .outermostMargin {
      background: $sm-bg-color-grey;
      color: $sm-text-color;
      font-size: $sm-font-size-lg;
      overflow: auto;
      height: 100vh; // margin: 41px 0 0 0;
      .ALittleBit{
        margin-top:54px;
        .carousel {
          margin: 0;
          padding: 0; // height: $sm-img-per-xm;
          // width: $sm-img-per-max;
          // background-image: url("../../assets/convenientService/thirdPage/problemSerBg.jpg");
          // background-repeat: no-repeat;
          // background-size: cover;
          // display: flex;
          // flex-direction: row;
          // justify-content: center;
          // align-items: center;
          // color: $sm-text-color-inverse;
          // font-size: $sm-font-sizeVH-base;
        }
        .listBox {
          background-color: $sm-bg-color;
          display: flex;
          flex-direction: column;
          position: absolute;
          left: 0;
          right: 0;
          top: 265px;
          bottom:40px;
          height: calc(100vh - 215px- 40px);
          overflow-y: auto;
          .van-divider {
            padding: 0px !important;
            margin: 0px !important;
          }
          .mainBox {
            padding: $sm-spaceing-block-base;
            display: flex;
            flex-direction: row;
            flex-wrap: nowrap;
            align-items: center;
            justify-content: space-between;
            position: relative;
            .phone {
              display: block;
              width: 40px;
              height: 40px;
              position: absolute;
              right: 15px; // bottom: 0px;
            }
            .leftP {
              display: flex;
              width: 100%; // flex-direction: row;
              // flex-wrap: nowrap;
              // align-items: center;
              // justify-content: space-around;
              align-items: center;
              .headp {
                width: 100px;
                margin-right: 15px;
              }
              .text {
                height: auto;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                width: 50vw;
                .namePhone {
                  display: flex;
                  flex-direction: row;
                  justify-content: space-between;
                  .itemname {
                    margin: 0 0 $sm-spaceing-block-mini $sm-spaceing-block-mini;
                    font-weight: bold;
                    text-overflow: -o-ellipsis-lastline;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 1;
                    line-clamp: 1;
                    -webkit-box-orient: vertical;
                    color: $sm-color-title;
                    line-height: $sm-font-size-xxl;
                  }
                  .item {
                    margin: 0 $sm-spaceing-block-mini $sm-spaceing-block-mini $sm-spaceing-block-mini;
                    font-size: $sm-font-sizeVH-sm;
                    color: $sm-text-color-li;
                  }
                }
                .posArea {
                  display: flex;
                  flex-direction: column;
                  .item {
                    margin: $sm-spaceing-block-xm;
                    font-size: $sm-font-sizeVH-sm;
                    color: $sm-text-color-li;
                  }
                }
              }
            }
          }
        }
      }
      .pages {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 111;
        background: #ffffff;
      }
    }
  }
</style>